/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Pojo.LoaiSach;
import Pojo.DanhMuc;
import Util.MySqlDataAccessHelper;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author USER
 */
public class LoaiSachDAO {
    //lấy danh sách thể loại

    public static List<LoaiSach> getList() {
        List<LoaiSach> dms = new ArrayList<LoaiSach>();
        
        try {
            String sql = "SELECT * FROM loai_sach";
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.open();
            ResultSet rs = helper.executeQuery(sql);
            while (rs.next()) {
                LoaiSach loaiSach = new LoaiSach();
                List<DanhMuc> danhMucs = new ArrayList<DanhMuc>();
                loaiSach.setMaLoaiSach(rs.getInt("ma_loai_sach"));
                loaiSach.setTenLoaiSach(rs.getString("ten_loai_sach"));
                danhMucs = DanhMucDAO.getList(loaiSach.getMaLoaiSach());
                loaiSach.setDanhMucs(danhMucs);
                dms.add(loaiSach); 
            }
            
            helper.close();
        } catch (Exception e) {
            
        }
        
        return  dms;
    }
}
